package com.zlzlib.libdialog;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;


import com.zlzlib.libdialog.adapter.NormalAdapter;
import com.zlzlib.libdialog.databinding.DialogBottomListBinding;

import java.util.List;


/**
 * Created by zlz on 2017/9/21.
 * 底部列表弹窗
 */

public class BottomListDialog extends BaseDialog<DialogBottomListBinding> {

    private TipListener btnListener;

    public BottomListDialog(Context context) {
        super(context);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.dialog_bottom_list;
    }

    protected void initView() {
        setDialogWH(1, 0);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        setLocBottom();
        mBinding.btn.setOnClickListener(view -> {
            dismiss();
            if (btnListener != null) btnListener.onclick();
        });
        mBinding.listView.setAdapter(adapter);
    }

    private final NormalAdapter<String> adapter = new NormalAdapter<String>(
            getContext(), R.layout.item_dialog) {

        @Override
        protected void convert(View convertView, List<String> data, int position) {
            TextView con = NormalAdapter.get(convertView, R.id.con);
            con.setText(data.get(position));
        }
    };

    public BottomListDialog setListValue(List<String> list, AdapterView.OnItemClickListener listener) {
        adapter.setData(list);
        mBinding.listView.setOnItemClickListener(listener);
        return this;
    }

    public BottomListDialog setListValue(List<String> list) {
        adapter.setData(list);
        return this;
    }

    public BottomListDialog setListItemClick(AdapterView.OnItemClickListener listener) {
        mBinding.listView.setOnItemClickListener(listener);
        return this;
    }

    public BottomListDialog setTitleText(String s) {
        mBinding.title.setText(s);
        return this;
    }

    public BottomListDialog setTitleColor(int c) {
        mBinding.title.setTextColor(c);
        return this;
    }

    public BottomListDialog setBtnText(String s) {
        mBinding.btn.setText(s);
        return this;
    }

    public BottomListDialog setBtnColor(int c) {
        mBinding.btn.setTextColor(c);
        return this;
    }

    public BottomListDialog setBtnListener(TipListener btnListener) {
        this.btnListener = btnListener;
        return this;
    }
}
